#define _CRT_SECURE_NO_WARNINGS 1
#include"Stack.h"
void STInit(ST* ps)
{
	ps->a = (STDataType *)malloc(sizeof(STDataType) * 4);
		if (ps == NULL)
		{
			perror("malloc fail");
			return;
		}
		ps->top = 0;
		ps->capacity = 4;
}
void STDestroy(ST* ps)
{
	assert(ps);
	free(ps->a);
	ps->top = 0;
	ps->capacity = 0;
}
void STPush(ST* ps, STDataType x)
{
	assert(ps);
	if (ps->top == ps->capacity)
	{
		STDataType* tmp = NULL;
		tmp = (STDataType*)realloc(ps->a, sizeof(STDataType) * ps->capacity * 2);
		if (tmp == NULL)
		{
			perror("realloc fail");
			return;
		}
		else
		{
			ps->a = tmp;
			ps->capacity *= 2;
		}
	}
	ps->a[ps->top++] = x;
}
void STPop(ST* ps)
{
	assert(ps);
	assert(ps->top);
	ps->top--;
}
int STSize(ST* ps)
{
	return ps->top;
}
bool STEmpty(ST* ps)
{
	return ps->top == 0;
}
STDataType STTop(ST* ps)
{
	assert(ps);
	assert(ps->top);
	return ps->a[(ps->top) - 1];
}

